/**
 *  联合类型(union)
 *  指定变量的类型可以是多种类型中的一种，中间用管道符(|)隔开
 *  
 */
let value: string|number
value = 'thc'
value = 1
function printId(id:number|string):void{
    if(typeof id === 'string'){
        console.log(id.toUpperCase())
    }
    else{
        console.log(`number ${id}`)
    }
}
printId('thc')
printId(100)
function welcomeFn(x:Array<string>|string){
    if(Array.isArray(x)){
        console.log('hero, '+x.join(' and '))
    }
    else{
        console.log(x + ' is a hero')
    }
}
welcomeFn(['thc', '我爱打水'])
welcomeFn('thc')
function dealNum(num?:number|null){
    console.log(typeof num!.toFixed(2))
    // let resNum:number = num!.toFixed(2) //通过toFixed处理后，数据类型为string
}
dealNum(3.14159)